home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tk4.0 / tkText.h < prev    next >
C/C++ Source or Header  |  1995-04-17  |  32KB  |  795 lines

  1. /*
  2.  * tkText.h --
  3.  *
  4.  *    Declarations shared among the files that implement text
  5.  *    widgets.
  6.  *
  7.  * Copyright (c) 1992-1994 The Regents of the University of California.
  8.  * Copyright (c) 1994-1995 Sun Microsystems, Inc.
  9.  *
  10.  * See the file "license.terms" for information on usage and redistribution
  11.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12.  *
  13.  * @(#) tkText.h 1.35 95/04/17 14:51:44
  14.  */
  15.  
  16. #ifndef _TKTEXT
  17. #define _TKTEXT
  18.  
  19. #ifndef _TK
  20. #include "tk.h"
  21. #endif
  22.  
  23. /*
  24.  * Opaque types for structures whose guts are only needed by a single
  25.  * file:
  26.  */
  27.  
  28. typedef struct TkTextBTree *TkTextBTree;
  29.  
  30. /*
  31.  * The data structure below defines a single line of text (from newline
  32.  * to newline, not necessarily what appears on one line of the screen).
  33.  */
  34.  
  35. typedef struct TkTextLine {
  36.     struct Node *parentPtr;        /* Pointer to parent node containing
  37.                      * line. */
  38.     struct TkTextLine *nextPtr;        /* Next in linked list of lines with
  39.                      * same parent node in B-tree.  NULL
  40.                      * means end of list. */
  41.     struct TkTextSegment *segPtr;    /* First in ordered list of segments
  42.                      * that make up the line. */
  43. } TkTextLine;
  44.  
  45. /*
  46.  * -----------------------------------------------------------------------
  47.  * Segments: each line is divided into one or more segments, where each
  48.  * segment is one of several things, such as a group of characters, a
  49.  * tag toggle, a mark, or an embedded widget.  Each segment starts with
  50.  * a standard header followed by a body that varies from type to type.
  51.  * -----------------------------------------------------------------------
  52.  */
  53.  
  54. /*
  55.  * The data structure below defines the body of a segment that represents
  56.  * a tag toggle.  There is one of these structures at both the beginning
  57.  * and end of each tagged range.
  58.  */
  59.  
  60. typedef struct TkTextToggle {
  61.     struct TkTextTag *tagPtr;        /* Tag that starts or ends here. */
  62.     int inNodeCounts;            /* 1 means this toggle has been
  63.                      * accounted for in node toggle
  64.                      * counts; 0 means it hasn't, yet. */
  65. } TkTextToggle;
  66.  
  67. /*
  68.  * The data structure below defines line segments that represent
  69.  * marks.  There is one of these for each mark in the text.
  70.  */
  71.  
  72. typedef struct TkTextMark {
  73.     struct TkText *textPtr;        /* Overall information about text
  74.                      * widget. */
  75.     TkTextLine *linePtr;        /* Line structure that contains the
  76.                      * segment. */
  77.     Tcl_HashEntry *hPtr;        /* Pointer to hash table entry for mark
  78.                      * (in textPtr->markTable). */
  79. } TkTextMark;
  80.  
  81. /*
  82.  * A structure of the following type holds information for each window
  83.  * embedded in a text widget.  This information is only used by the
  84.  * file tkTextWind.c
  85.  */
  86.  
  87. typedef struct TkTextEmbWindow {
  88.     struct TkText *textPtr;        /* Information about the overall text
  89.                      * widget. */
  90.     TkTextLine *linePtr;        /* Line structure that contains this
  91.                      * window. */
  92.     Tk_Window tkwin;            /* Window for this segment.  NULL
  93.                      * means that the window hasn't
  94.                      * been created yet. */
  95.     char *create;            /* Script to create window on-demand.
  96.                      * NULL means no such script.
  97.                      * Malloc-ed. */
  98.     int align;                /* How to align window in vertical
  99.                      * space.  See definitions in
  100.                      * tkTextWind.c. */
  101.     int padX, padY;            /* Padding to leave around each side
  102.                      * of window, in pixels. */
  103.     int stretch;            /* Should window stretch to fill
  104.                      * vertical space of line (except for
  105.                      * pady)?  0 or 1. */
  106.     int chunkCount;            /* Number of display chunks that
  107.                      * refer to this window. */
  108.     int displayed;            /* Non-zero means that the window
  109.                      * has been displayed on the screen
  110.                      * recently. */
  111. } TkTextEmbWindow;
  112.  
  113. /*
  114.  * The data structure below defines line segments.
  115.  */
  116.  
  117. typedef struct TkTextSegment {
  118.     struct Tk_SegType *typePtr;        /* Pointer to record describing
  119.                      * segment's type. */
  120.     struct TkTextSegment *nextPtr;    /* Next in list of segments for this
  121.                      * line, or NULL for end of list. */
  122.     int size;                /* Size of this segment (# of bytes
  123.                      * of index space it occupies). */
  124.     union {
  125.     char chars[4];            /* Characters that make up character
  126.                      * info.  Actual length varies to
  127.                      * hold as many characters as needed.*/
  128.     TkTextToggle toggle;        /* Information about tag toggle. */
  129.     TkTextMark mark;        /* Information about mark. */
  130.     TkTextEmbWindow ew;        /* Information about embedded
  131.                      * window. */
  132.     } body;
  133. } TkTextSegment;
  134.  
  135. /*
  136.  * Data structures of the type defined below are used during the
  137.  * execution of Tcl commands to keep track of various interesting
  138.  * places in a text.  An index is only valid up until the next
  139.  * modification to the character structure of the b-tree so they
  140.  * can't be retained across Tcl commands.  However, mods to marks
  141.  * or tags don't invalidate indices.
  142.  */
  143.  
  144. typedef struct TkTextIndex {
  145.     TkTextBTree tree;            /* Tree containing desired position. */
  146.     TkTextLine *linePtr;        /* Pointer to line containing position
  147.                      * of interest. */
  148.     int charIndex;            /* Index within line of desired
  149.                      * character (0 means first one). */
  150. } TkTextIndex;
  151.  
  152. /*
  153.  * Types for procedure pointers stored in TkTextDispChunk strutures:
  154.  */
  155.  
  156. typedef struct TkTextDispChunk TkTextDispChunk;
  157.  
  158. typedef void         Tk_ChunkDisplayProc _ANSI_ARGS_((
  159.                 TkTextDispChunk *chunkPtr, int x, int y,
  160.                 int height, int baseline, Display *display,
  161.                 Drawable dst, int screenY));
  162. typedef void        Tk_ChunkUndisplayProc _ANSI_ARGS_((
  163.                 struct TkText *textPtr,
  164.                 TkTextDispChunk *chunkPtr));
  165. typedef int        Tk_ChunkMeasureProc _ANSI_ARGS_((
  166.                 TkTextDispChunk *chunkPtr, int x));
  167. typedef void        Tk_ChunkBboxProc _ANSI_ARGS_((
  168.                 TkTextDispChunk *chunkPtr, int index, int y,
  169.                 int lineHeight, int baseline, int *xPtr,
  170.                 int *yPtr, int *widthPtr, int *heightPtr));
  171.  
  172. /*
  173.  * The structure below represents a chunk of stuff that is displayed
  174.  * together on the screen.  This structure is allocated and freed by
  175.  * generic display code but most of its fields are filled in by
  176.  * segment-type-specific code.
  177.  */
  178.  
  179. struct TkTextDispChunk {
  180.     /*
  181.      * The fields below are set by the type-independent code before
  182.      * calling the segment-type-specific layoutProc.  They should not
  183.      * be modified by segment-type-specific code.
  184.      */
  185.  
  186.     int x;                /* X position of chunk, in pixels.
  187.                      * This position is measured from the
  188.                      * left edge of the logical line,
  189.                      * not from the left edge of the
  190.                      * window (i.e. it doesn't change
  191.                      * under horizontal scrolling). */
  192.     struct TkTextDispChunk *nextPtr;    /* Next chunk in the display line
  193.                      * or NULL for the end of the list. */
  194.     struct Style *stylePtr;        /* Display information, known only
  195.                      * to tkTextDisp.c. */
  196.  
  197.     /*
  198.      * The fields below are set by the layoutProc that creates the
  199.      * chunk.
  200.      */
  201.  
  202.     Tk_ChunkDisplayProc *displayProc;    /* Procedure to invoke to draw this
  203.                      * chunk on the display or an
  204.                      * off-screen pixmap. */
  205.     Tk_ChunkUndisplayProc *undisplayProc;
  206.                     /* Procedure to invoke when segment
  207.                      * ceases to be displayed on screen
  208.                      * anymore. */
  209.     Tk_ChunkMeasureProc *measureProc;    /* Procedure to find character under
  210.                      * a given x-location. */
  211.     Tk_ChunkBboxProc *bboxProc;        /* Procedure to find bounding box
  212.                      * of character in chunk. */
  213.     int numChars;            /* Number of characters that will be
  214.                      * displayed in the chunk. */
  215.     int minAscent;            /* Minimum space above the baseline
  216.                      * needed by this chunk. */
  217.     int minDescent;            /* Minimum space below the baseline
  218.                      * needed by this chunk. */
  219.     int minHeight;            /* Minimum total line height needed
  220.                      * by this chunk. */
  221.     int width;                /* Width of this chunk, in pixels.
  222.                      * Initially set by chunk-specific
  223.                      * code, but may be increased to
  224.                      * include tab or extra space at end
  225.                      * of line. */
  226.     int breakIndex;            /* Index within chunk of last
  227.                      * acceptable position for a line
  228.                      * (break just before this character).
  229.                      * <= 0 means don't break during or
  230.                      * immediately after this chunk. */
  231.     ClientData clientData;        /* Additional information for use
  232.                      * of displayProc and undisplayProc. */
  233. };
  234.  
  235. /*
  236.  * One data structure of the following type is used for each tag in a
  237.  * text widget.  These structures are kept in textPtr->tagTable and
  238.  * referred to in other structures.
  239.  */
  240.  
  241. typedef struct TkTextTag {
  242.     char *name;            /* Name of this tag.  This field is actually
  243.                  * a pointer to the key from the entry in
  244.                  * textPtr->tagTable, so it needn't be freed
  245.                  * explicitly. */
  246.     int priority;        /* Priority of this tag within widget.  0
  247.                  * means lowest priority.  Exactly one tag
  248.                  * has each integer value between 0 and
  249.                  * numTags-1. */
  250.  
  251.     /*
  252.      * Information for displaying text with this tag.  The information
  253.      * belows acts as an override on information specified by lower-priority
  254.      * tags.  If no value is specified, then the next-lower-priority tag
  255.      * on the text determins the value.  The text widget itself provides
  256.      * defaults if no tag specifies an override.
  257.      */
  258.  
  259.     Tk_3DBorder border;        /* Used for drawing background.  NULL means
  260.                  * no value specified here. */
  261.     char *bdString;        /* -borderwidth option string (malloc-ed).
  262.                  * NULL means option not specified. */
  263.     int borderWidth;        /* Width of 3-D border for background. */
  264.     char *reliefString;        /* -relief option string (malloc-ed).
  265.                  * NULL means option not specified. */
  266.     int relief;            /* 3-D relief for background. */
  267.     Pixmap bgStipple;        /* Stipple bitmap for background.  None
  268.                  * means no value specified here. */
  269.     XColor *fgColor;        /* Foreground color for text.  NULL means
  270.                  * no value specified here. */
  271.     XFontStruct *fontPtr;    /* Font for displaying text.  NULL means
  272.                  * no value specified here. */
  273.     Pixmap fgStipple;        /* Stipple bitmap for text and other
  274.                  * foreground stuff.   None means no value
  275.                  * specified here.*/
  276.     char *justifyString;    /* -justify option string (malloc-ed).
  277.                  * NULL means option not specified. */
  278.     Tk_Justify justify;        /* How to justify text: TK_JUSTIFY_LEFT,
  279.                  * TK_JUSTIFY_RIGHT, or TK_JUSTIFY_CENTER.
  280.                  * Only valid if justifyString is non-NULL. */
  281.     char *lMargin1String;    /* -lmargin1 option string (malloc-ed).
  282.                  * NULL means option not specified. */
  283.     int lMargin1;        /* Left margin for first display line of
  284.                  * each text line, in pixels.  Only valid
  285.                  * if lMargin1String is non-NULL. */
  286.     char *lMargin2String;    /* -lmargin2 option string (malloc-ed).
  287.                  * NULL means option not specified. */
  288.     int lMargin2;        /* Left margin for second and later display
  289.                  * lines of each text line, in pixels.  Only
  290.                  * valid if lMargin2String is non-NULL. */
  291.     char *offsetString;        /* -offset option string (malloc-ed).
  292.                  * NULL means option not specified. */
  293.     int offset;            /* Vertical offset of text's baseline from
  294.                  * baseline of line.  Used for superscripts
  295.                  * and subscripts.  Only valid if
  296.                  * offsetString is non-NULL. */
  297.     char *overstrikeString;    /* -overstrike option string (malloc-ed).
  298.                  * NULL means option not specified. */
  299.     int overstrike;        /* Non-zero means draw horizontal line through
  300.                  * middle of text.  Only valid if
  301.                  * overstrikeString is non-NULL. */
  302.     char *rMarginString;    /* -rmargin option string (malloc-ed).
  303.                  * NULL means option not specified. */
  304.     int rMargin;        /* Right margin for text, in pixels.  Only
  305.                  * valid if rMarginString is non-NULL. */
  306.     char *spacing1String;    /* -spacing1 option string (malloc-ed).
  307.                  * NULL means option not specified. */
  308.     int spacing1;        /* Extra spacing above first display
  309.                  * line for text line.  Only valid if
  310.                  * spacing1String is non-NULL. */
  311.     char *spacing2String;    /* -spacing2 option string (malloc-ed).
  312.                  * NULL means option not specified. */
  313.     int spacing2;        /* Extra spacing between display
  314.                  * lines for the same text line.  Only valid
  315.                  * if spacing2String is non-NULL. */
  316.     char *spacing3String;    /* -spacing2 option string (malloc-ed).
  317.                  * NULL means option not specified. */
  318.     int spacing3;        /* Extra spacing below last display
  319.                  * line for text line.  Only valid if
  320.                  * spacing3String is non-NULL. */
  321.     char *tabString;        /* -tabs option string (malloc-ed).
  322.                  * NULL means option not specified. */
  323.     struct TkTextTabArray *tabArrayPtr;
  324.                 /* Info about tabs for tag (malloc-ed)
  325.                  * or NULL.  Corresponds to tabString. */
  326.     char *underlineString;    /* -underline option string (malloc-ed).
  327.                  * NULL means option not specified. */
  328.     int underline;        /* Non-zero means draw underline underneath
  329.                  * text.  Only valid if underlineString is
  330.                  * non-NULL. */
  331.     Tk_Uid wrapMode;        /* How to handle wrap-around for this tag.
  332.                  * Must be tkTextCharUid, tkTextNoneUid,
  333.                  * tkTextWordUid, or NULL to use wrapMode
  334.                  * for whole widget. */
  335.     int affectsDisplay;        /* Non-zero means that this tag affects the
  336.                  * way information is displayed on the screen
  337.                  * (so need to redisplay if tag changes). */
  338. } TkTextTag;
  339.  
  340. #define TK_TAG_AFFECTS_DISPLAY    0x1
  341. #define TK_TAG_UNDERLINE    0x2
  342. #define TK_TAG_JUSTIFY        0x4
  343. #define TK_TAG_OFFSET        0x10
  344.  
  345. /*
  346.  * The data structure below is used for searching a B-tree for transitions
  347.  * on a single tag (or for all tag transitions).  No code outside of
  348.  * tkTextBTree.c should ever modify any of the fields in these structures,
  349.  * but it's OK to use them for read-only information.
  350.  */
  351.  
  352. typedef struct TkTextSearch {
  353.     TkTextIndex curIndex;        /* Position of last tag transition
  354.                      * returned by TkBTreeNextTag, or
  355.                      * index of start of segment
  356.                      * containing starting position for
  357.                      * search if TkBTreeNextTag hasn't
  358.                      * been called yet, or same as
  359.                      * stopIndex if search is over. */
  360.     TkTextSegment *segPtr;        /* Actual tag segment returned by last
  361.                      * call to TkBTreeNextTag, or NULL if
  362.                      * TkBTreeNextTag hasn't returned
  363.                      * anything yet. */
  364.     TkTextSegment *nextPtr;        /* Where to resume search in next
  365.                      * call to TkBTreeNextTag. */
  366.     TkTextSegment *lastPtr;        /* Stop search before just before
  367.                      * considering this segment. */
  368.     TkTextTag *tagPtr;            /* Tag to search for (or tag found, if
  369.                      * allTags is non-zero). */
  370.     int linesLeft;            /* Lines left to search (including
  371.                      * curIndex and stopIndex).  When
  372.                      * this becomes <= 0 the search is
  373.                      * over. */
  374.     int allTags;            /* Non-zero means ignore tag check:
  375.                      * search for transitions on all
  376.                      * tags. */
  377. } TkTextSearch;
  378.  
  379. /*
  380.  * The following data structure describes a single tab stop.
  381.  */
  382.  
  383. typedef enum {LEFT, RIGHT, CENTER, NUMERIC} TkTextTabAlign;
  384.  
  385. typedef struct TkTextTab {
  386.     int location;            /* Offset in pixels of this tab stop
  387.                      * from the left margin (lmargin2) of
  388.                      * the text. */
  389.     TkTextTabAlign alignment;        /* Where the tab stop appears relative
  390.                      * to the text. */
  391. } TkTextTab;
  392.  
  393. typedef struct TkTextTabArray {
  394.     int numTabs;            /* Number of tab stops. */
  395.     TkTextTab tabs[1];            /* Array of tabs.  The actual size
  396.                      * will be numTabs.  THIS FIELD MUST
  397.                      * BE THE LAST IN THE STRUCTURE. */
  398. } TkTextTabArray;
  399.  
  400. /*
  401.  * A data structure of the following type is kept for each text widget that
  402.  * currently exists for this process:
  403.  */
  404.  
  405. typedef struct TkText {
  406.     Tk_Window tkwin;        /* Window that embodies the text.  NULL
  407.                  * means that the window has been destroyed
  408.                  * but the data structures haven't yet been
  409.                  * cleaned up.*/
  410.     Display *display;        /* Display for widget.  Needed, among other
  411.                  * things, to allow resources to be freed
  412.                  * even after tkwin has gone away. */
  413.     Tcl_Interp *interp;        /* Interpreter associated with widget.  Used
  414.                  * to delete widget command.  */
  415.     Tcl_Command widgetCmd;    /* Token for text's widget command. */
  416.     TkTextBTree tree;        /* B-tree representation of text and tags for
  417.                  * widget. */
  418.     Tcl_HashTable tagTable;    /* Hash table that maps from tag names to
  419.                  * pointers to TkTextTag structures. */
  420.     int numTags;        /* Number of tags currently defined for
  421.                  * widget;  needed to keep track of
  422.                  * priorities. */
  423.     Tcl_HashTable markTable;    /* Hash table that maps from mark names to
  424.                  * pointers to mark segments. */
  425.     Tcl_HashTable windowTable;    /* Hash table that maps from window names
  426.                  * to pointers to window segments.  If a
  427.                  * window segment doesn't yet have an
  428.                  * associated window, there is no entry for
  429.                  * it here. */
  430.     Tk_Uid state;        /* Normal or disabled.  Text is read-only
  431.                  * when disabled. */
  432.  
  433.     /*
  434.      * Default information for displaying (may be overridden by tags
  435.      * applied to ranges of characters).
  436.      */
  437.  
  438.     Tk_3DBorder border;        /* Structure used to draw 3-D border and
  439.                  * default background. */
  440.     int borderWidth;        /* Width of 3-D border to draw around entire
  441.                  * widget. */
  442.     int padX, padY;        /* Padding between text and window border. */
  443.     int relief;            /* 3-d effect for border around entire
  444.                  * widget: TK_RELIEF_RAISED etc. */
  445.     int highlightWidth;        /* Width in pixels of highlight to draw
  446.                  * around widget when it has the focus.
  447.                  * <= 0 means don't draw a highlight. */
  448.     XColor *highlightBgColorPtr;
  449.                 /* Color for drawing traversal highlight
  450.                  * area when highlight is off. */
  451.     XColor *highlightColorPtr;    /* Color for drawing traversal highlight. */
  452.     Cursor cursor;        /* Current cursor for window, or None. */
  453.     XColor *fgColor;        /* Default foreground color for text. */
  454.     XFontStruct *fontPtr;    /* Default font for displaying text. */
  455.     int charWidth;        /* Width of average character in default
  456.                  * font. */
  457.     int spacing1;        /* Default extra spacing above first display
  458.                  * line for each text line. */
  459.     int spacing2;        /* Default extra spacing between display lines
  460.                  * for the same text line. */
  461.     int spacing3;        /* Default extra spacing below last display
  462.                  * line for each text line. */
  463.     char *tabOptionString;    /* Value of -tabs option string (malloc'ed). */
  464.     TkTextTabArray *tabArrayPtr;
  465.                 /* Information about tab stops (malloc'ed).
  466.                  * NULL means perform default tabbing
  467.                  * behavior. */
  468.  
  469.     /*
  470.      * Additional information used for displaying:
  471.      */
  472.  
  473.     Tk_Uid wrapMode;        /* How to handle wrap-around.  Must be
  474.                  * tkTextCharUid, tkTextNoneUid, or
  475.                  * tkTextWordUid. */
  476.     int width, height;        /* Desired dimensions for window, measured
  477.                  * in characters. */
  478.     int setGrid;        /* Non-zero means pass gridding information
  479.                  * to window manager. */
  480.     int prevWidth, prevHeight;    /* Last known dimensions of window;  used to
  481.                  * detect changes in size. */
  482.     TkTextIndex topIndex;    /* Identifies first character in top display
  483.                  * line of window. */
  484.     struct DInfo *dInfoPtr;    /* Information maintained by tkTextDisp.c. */
  485.  
  486.     /*
  487.      * Information related to selection.
  488.      */
  489.  
  490.     TkTextTag *selTagPtr;    /* Pointer to "sel" tag.  Used to tell when
  491.                  * a new selection has been made. */
  492.     Tk_3DBorder selBorder;    /* Border and background for selected
  493.                  * characters.  This is a copy of information
  494.                  * in *cursorTagPtr, so it shouldn't be
  495.                  * explicitly freed. */
  496.     char *selBdString;        /* Value of -selectborderwidth option, or NULL
  497.                  * if not specified (malloc'ed). */
  498.     XColor *selFgColorPtr;    /* Foreground color for selected text.
  499.                  * This is a copy of information in
  500.                  * *cursorTagPtr, so it shouldn't be
  501.                  * explicitly freed. */
  502.     int exportSelection;    /* Non-zero means tie "sel" tag to X
  503.                  * selection. */
  504.     TkTextIndex selIndex;    /* Used during multi-pass selection retrievals.
  505.                  * This index identifies the next character
  506.                  * to be returned from the selection. */
  507.     int abortSelections;    /* Set to 1 whenever the text is modified
  508.                  * in a way that interferes with selection
  509.                  * retrieval:  used to abort incremental
  510.                  * selection retrievals. */
  511.     int selOffset;        /* Offset in selection corresponding to
  512.                  * selLine and selCh.  -1 means neither
  513.                  * this information nor selIndex is of any
  514.                  * use. */
  515.  
  516.     /*
  517.      * Information related to insertion cursor:
  518.      */
  519.  
  520.     TkTextSegment *insertMarkPtr;
  521.                 /* Points to segment for "insert" mark. */
  522.     Tk_3DBorder insertBorder;    /* Used to draw vertical bar for insertion
  523.                  * cursor. */
  524.     int insertWidth;        /* Total width of insert cursor. */
  525.     int insertBorderWidth;    /* Width of 3-D border around insert cursor. */
  526.     int insertOnTime;        /* Number of milliseconds cursor should spend
  527.                  * in "on" state for each blink. */
  528.     int insertOffTime;        /* Number of milliseconds cursor should spend
  529.                  * in "off" state for each blink. */
  530.     Tk_TimerToken insertBlinkHandler;
  531.                 /* Timer handler used to blink cursor on and
  532.                  * off. */
  533.  
  534.     /*
  535.      * Information used for event bindings associated with tags:
  536.      */
  537.  
  538.     Tk_BindingTable bindingTable;
  539.                 /* Table of all bindings currently defined
  540.                  * for this widget.  NULL means that no
  541.                  * bindings exist, so the table hasn't been
  542.                  * created.  Each "object" used for this
  543.                  * table is the address of a tag. */
  544.     TkTextSegment *currentMarkPtr;
  545.                 /* Pointer to segment for "current" mark,
  546.                  * or NULL if none. */
  547.     XEvent pickEvent;        /* The event from which the current character
  548.                  * was chosen.  Must be saved so that we
  549.                  * can repick after modifications to the
  550.                  * text. */
  551.     int numCurTags;        /* Number of tags associated with character
  552.                  * at current mark. */
  553.     TkTextTag **curTagArrayPtr;    /* Pointer to array of tags for current
  554.                  * mark, or NULL if none. */
  555.  
  556.     /*
  557.      * Miscellaneous additional information:
  558.      */
  559.  
  560.     char *takeFocus;        /* Value of -takeFocus option;  not used in
  561.                  * the C code, but used by keyboard traversal
  562.                  * scripts.  Malloc'ed, but may be NULL. */
  563.     char *xScrollCmd;        /* Prefix of command to issue to update
  564.                  * horizontal scrollbar when view changes. */
  565.     char *yScrollCmd;        /* Prefix of command to issue to update
  566.                  * vertical scrollbar when view changes. */
  567.     int flags;            /* Miscellaneous flags;  see below for
  568.                  * definitions. */
  569. } TkText;
  570.  
  571. /*
  572.  * Flag values for TkText records:
  573.  *
  574.  * GOT_SELECTION:        Non-zero means we've already claimed the
  575.  *                selection.
  576.  * INSERT_ON:            Non-zero means insertion cursor should be
  577.  *                displayed on screen.
  578.  * GOT_FOCUS:            Non-zero means this window has the input
  579.  *                focus.
  580.  * BUTTON_DOWN:            1 means that a mouse button is currently
  581.  *                down;  this is used to implement grabs
  582.  *                for the duration of button presses.
  583.  * UPDATE_SCROLLBARS:        Non-zero means scrollbar(s) should be updated
  584.  *                during next redisplay operation.
  585.  */
  586.  
  587. #define GOT_SELECTION        1
  588. #define INSERT_ON        2
  589. #define GOT_FOCUS        4
  590. #define BUTTON_DOWN        8
  591. #define UPDATE_SCROLLBARS    0x10
  592. #define NEED_REPICK        0x20
  593.  
  594. /*
  595.  * Records of the following type define segment types in terms of
  596.  * a collection of procedures that may be called to manipulate
  597.  * segments of that type.
  598.  */
  599.  
  600. typedef TkTextSegment *    Tk_SegSplitProc _ANSI_ARGS_((
  601.                 struct TkTextSegment *segPtr, int index));
  602. typedef int        Tk_SegDeleteProc _ANSI_ARGS_((
  603.                 struct TkTextSegment *segPtr,
  604.                 TkTextLine *linePtr, int treeGone));
  605. typedef TkTextSegment *    Tk_SegCleanupProc _ANSI_ARGS_((
  606.                 struct TkTextSegment *segPtr, TkTextLine *linePtr));
  607. typedef void        Tk_SegLineChangeProc _ANSI_ARGS_((
  608.                 struct TkTextSegment *segPtr, TkTextLine *linePtr));
  609. typedef int        Tk_SegLayoutProc _ANSI_ARGS_((struct TkText *textPtr,
  610.                 struct TkTextIndex *indexPtr, TkTextSegment *segPtr,
  611.                 int offset, int maxX, int maxChars,
  612.                 int noCharsYet, Tk_Uid wrapMode,
  613.                 struct TkTextDispChunk *chunkPtr));
  614. typedef void        Tk_SegCheckProc _ANSI_ARGS_((TkTextSegment *segPtr,
  615.                 TkTextLine *linePtr));
  616.  
  617. typedef struct Tk_SegType {
  618.     char *name;                /* Name of this kind of segment. */
  619.     int leftGravity;            /* If a segment has zero size (e.g. a
  620.                      * mark or tag toggle), does it
  621.                      * attach to character to its left
  622.                      * or right?  1 means left, 0 means
  623.                      * right. */
  624.     Tk_SegSplitProc *splitProc;        /* Procedure to split large segment
  625.                      * into two smaller ones. */
  626.     Tk_SegDeleteProc *deleteProc;    /* Procedure to call to delete
  627.                      * segment. */
  628.     Tk_SegCleanupProc *cleanupProc;    /* After any change to a line, this
  629.                      * procedure is invoked for all
  630.                      * segments left in the line to
  631.                      * perform any cleanup they wish
  632.                      * (e.g. joining neighboring
  633.                      * segments). */
  634.     Tk_SegLineChangeProc *lineChangeProc;
  635.                     /* Invoked when a segment is about
  636.                      * to be moved from its current line
  637.                      * to some other line (cleanupProc
  638.                      * will be called later with the
  639.                      * new line). */
  640.     Tk_SegLayoutProc *layoutProc;    /* Returns size information when
  641.                      * figuring out what to display in
  642.                      * window. */
  643.     Tk_SegCheckProc *checkProc;        /* Called during consistency checks
  644.                      * to check internal consistency of
  645.                      * segment. */
  646. } Tk_SegType;
  647.  
  648. /*
  649.  * The constant below is used to specify a line when what is really
  650.  * wanted is the entire text.  For now, just use a very big number.
  651.  */
  652.  
  653. #define TK_END_OF_TEXT 1000000
  654.  
  655. /*
  656.  * The following definition specifies the maximum number of characters
  657.  * needed in a string to hold a position specifier.
  658.  */
  659.  
  660. #define TK_POS_CHARS 30
  661.  
  662. /*
  663.  * Declarations for variables shared among the text-related files:
  664.  */
  665.  
  666. extern int        tkBTreeDebug;
  667. extern int        tkTextDebug;
  668. extern Tk_SegType    tkTextCharType;
  669. extern Tk_Uid        tkTextCharUid;
  670. extern Tk_Uid        tkTextDisabledUid;
  671. extern Tk_SegType    tkTextLeftMarkType;
  672. extern Tk_Uid        tkTextNoneUid;
  673. extern Tk_Uid         tkTextNormalUid;
  674. extern Tk_SegType    tkTextRightMarkType;
  675. extern Tk_SegType    tkTextToggleOnType;
  676. extern Tk_SegType    tkTextToggleOffType;
  677. extern Tk_Uid        tkTextWordUid;
  678.  
  679. /*
  680.  * Declarations for procedures that are used by the text-related files
  681.  * but shouldn't be used anywhere else in Tk (or by Tk clients):
  682.  */
  683.  
  684. extern int        TkBTreeCharTagged _ANSI_ARGS_((TkTextIndex *indexPtr,
  685.                 TkTextTag *tagPtr));
  686. extern void        TkBTreeCheck _ANSI_ARGS_((TkTextBTree tree));
  687. extern int        TkBTreeCharsInLine _ANSI_ARGS_((TkTextLine *linePtr));
  688. extern TkTextBTree    TkBTreeCreate _ANSI_ARGS_((void));
  689. extern void        TkBTreeDestroy _ANSI_ARGS_((TkTextBTree tree));
  690. extern void        TkBTreeDeleteChars _ANSI_ARGS_((TkTextIndex *index1Ptr,
  691.                 TkTextIndex *index2Ptr));
  692. extern TkTextLine *    TkBTreeFindLine _ANSI_ARGS_((TkTextBTree tree,
  693.                 int line));
  694. extern TkTextTag **    TkBTreeGetTags _ANSI_ARGS_((TkTextIndex *indexPtr,
  695.                 int *numTagsPtr));
  696. extern void        TkBTreeInsertChars _ANSI_ARGS_((TkTextIndex *indexPtr,
  697.                 char *string));
  698. extern int        TkBTreeLineIndex _ANSI_ARGS_((TkTextLine *linePtr));
  699. extern void        TkBTreeLinkSegment _ANSI_ARGS_((TkTextSegment *segPtr,
  700.                 TkTextIndex *indexPtr));
  701. extern TkTextLine *    TkBTreeNextLine _ANSI_ARGS_((TkTextLine *linePtr));
  702. extern int        TkBTreeNextTag _ANSI_ARGS_((TkTextSearch *searchPtr));
  703. extern int        TkBTreeNumLines _ANSI_ARGS_((TkTextBTree tree));
  704. extern void        TkBTreeStartSearch _ANSI_ARGS_((TkTextIndex *index1Ptr,
  705.                 TkTextIndex *index2Ptr, TkTextTag *tagPtr,
  706.                 TkTextSearch *searchPtr));
  707. extern void        TkBTreeTag _ANSI_ARGS_((TkTextIndex *index1Ptr,
  708.                 TkTextIndex *index2Ptr, TkTextTag *tagPtr,
  709.                 int add));
  710. extern void        TkBTreeUnlinkSegment _ANSI_ARGS_((TkTextBTree tree,
  711.                 TkTextSegment *segPtr, TkTextLine *linePtr));
  712. extern void        TkTextBindProc _ANSI_ARGS_((ClientData clientData,
  713.                 XEvent *eventPtr));
  714. extern void        TkTextChanged _ANSI_ARGS_((TkText *textPtr,
  715.                 TkTextIndex *index1Ptr, TkTextIndex *index2Ptr));
  716. extern int        TkTextCharBbox _ANSI_ARGS_((TkText *textPtr,
  717.                 TkTextIndex *indexPtr, int *xPtr, int *yPtr,
  718.                 int *widthPtr, int *heightPtr));
  719. extern int        TkTextCharLayoutProc _ANSI_ARGS_((TkText *textPtr,
  720.                 TkTextIndex *indexPtr, TkTextSegment *segPtr,
  721.                 int offset, int maxX, int maxChars, int noBreakYet,
  722.                 Tk_Uid wrapMode, TkTextDispChunk *chunkPtr));
  723. extern void        TkTextCreateDInfo _ANSI_ARGS_((TkText *textPtr));
  724. extern int        TkTextDLineInfo _ANSI_ARGS_((TkText *textPtr,
  725.                 TkTextIndex *indexPtr, int *xPtr, int *yPtr,
  726.                 int *widthPtr, int *heightPtr, int *basePtr));
  727. extern TkTextTag *    TkTextCreateTag _ANSI_ARGS_((TkText *textPtr,
  728.                 char *tagName));
  729. extern void        TkTextFreeDInfo _ANSI_ARGS_((TkText *textPtr));
  730. extern void        TkTextFreeTag _ANSI_ARGS_((TkText *textPtr,
  731.                 TkTextTag *tagPtr));
  732. extern int        TkTextGetIndex _ANSI_ARGS_((Tcl_Interp *interp,
  733.                 TkText *textPtr, char *string,
  734.                 TkTextIndex *indexPtr));
  735. extern TkTextTabArray *    TkTextGetTabs _ANSI_ARGS_((Tcl_Interp *interp,
  736.                 Tk_Window tkwin, char *string));
  737. extern void        TkTextIndexBackChars _ANSI_ARGS_((TkTextIndex *srcPtr,
  738.                 int count, TkTextIndex *dstPtr));
  739. extern int        TkTextIndexCmp _ANSI_ARGS_((TkTextIndex *index1Ptr,
  740.                 TkTextIndex *index2Ptr));
  741. extern void        TkTextIndexForwChars _ANSI_ARGS_((TkTextIndex *srcPtr,
  742.                 int count, TkTextIndex *dstPtr));
  743. extern TkTextSegment *    TkTextIndexToSeg _ANSI_ARGS_((TkTextIndex *indexPtr,
  744.                 int *offsetPtr));
  745. extern void        TkTextInsertDisplayProc _ANSI_ARGS_((
  746.                 TkTextDispChunk *chunkPtr, int x, int y, int height,
  747.                 int baseline, Display *display, Drawable dst,
  748.                 int screenY));
  749. extern void        TkTextLostSelection _ANSI_ARGS_((
  750.                 ClientData clientData));
  751. extern TkTextIndex *    TkTextMakeIndex _ANSI_ARGS_((TkTextBTree tree,
  752.                 int lineIndex, int charIndex,
  753.                 TkTextIndex *indexPtr));
  754. extern int        TkTextMarkCmd _ANSI_ARGS_((TkText *textPtr,
  755.                 Tcl_Interp *interp, int argc, char **argv));
  756. extern int        TkTextMarkNameToIndex _ANSI_ARGS_((TkText *textPtr,
  757.                 char *name, TkTextIndex *indexPtr));
  758. extern void        TkTextMarkSegToIndex _ANSI_ARGS_((TkText *textPtr,
  759.                 TkTextSegment *markPtr, TkTextIndex *indexPtr));
  760. extern void        TkTextEventuallyRepick _ANSI_ARGS_((TkText *textPtr));
  761. extern void        TkTextPickCurrent _ANSI_ARGS_((TkText *textPtr,
  762.                 XEvent *eventPtr));
  763. extern void        TkTextPixelIndex _ANSI_ARGS_((TkText *textPtr,
  764.                 int x, int y, TkTextIndex *indexPtr));
  765. extern void        TkTextPrintIndex _ANSI_ARGS_((TkTextIndex *indexPtr,
  766.                 char *string));
  767. extern void        TkTextRedrawRegion _ANSI_ARGS_((TkText *textPtr,
  768.                 int x, int y, int width, int height));
  769. extern void        TkTextRedrawTag _ANSI_ARGS_((TkText *textPtr,
  770.                 TkTextIndex *index1Ptr, TkTextIndex *index2Ptr,
  771.                 TkTextTag *tagPtr, int withTag));
  772. extern void        TkTextRelayoutWindow _ANSI_ARGS_((TkText *textPtr));
  773. extern int        TkTextScanCmd _ANSI_ARGS_((TkText *textPtr,
  774.                 Tcl_Interp *interp, int argc, char **argv));
  775. extern int        TkTextSeeCmd _ANSI_ARGS_((TkText *textPtr,
  776.                 Tcl_Interp *interp, int argc, char **argv));
  777. extern int        TkTextSegToOffset _ANSI_ARGS_((TkTextSegment *segPtr,
  778.                 TkTextLine *linePtr));
  779. extern TkTextSegment *    TkTextSetMark _ANSI_ARGS_((TkText *textPtr, char *name,
  780.                 TkTextIndex *indexPtr));
  781. extern void        TkTextSetYView _ANSI_ARGS_((TkText *textPtr,
  782.                 TkTextIndex *indexPtr, int pickPlace));
  783. extern int        TkTextTagCmd _ANSI_ARGS_((TkText *textPtr,
  784.                 Tcl_Interp *interp, int argc, char **argv));
  785. extern int        TkTextWindowCmd _ANSI_ARGS_((TkText *textPtr,
  786.                 Tcl_Interp *interp, int argc, char **argv));
  787. extern int        TkTextWindowIndex _ANSI_ARGS_((TkText *textPtr,
  788.                 char *name, TkTextIndex *indexPtr));
  789. extern int        TkTextXviewCmd _ANSI_ARGS_((TkText *textPtr,
  790.                 Tcl_Interp *interp, int argc, char **argv));
  791. extern int        TkTextYviewCmd _ANSI_ARGS_((TkText *textPtr,
  792.                 Tcl_Interp *interp, int argc, char **argv));
  793.  
  794. #endif /* _TKTEXT */
  795.